package cn.scau.server.pojo;

import cn.scau.server.service.Component;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 *
 * </p>
 *
 * @author 代码不跑我先跑
 * @since 2025-03-30
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="Dept对象", description="")
public class Dept implements Serializable, Component {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "唯一标识每个部门")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "部门的名称，如“技术部”、“市场部”等")
    private String name;

    @ApiModelProperty(value = "父部门的编号，用于表示部门的层级关系")
    private Integer parentId;

    @ApiModelProperty(value = "子部门和子员工")
    @TableField(exist = false) //让mybatisPlus忽略此字段的映射
    private List<Component> children = new ArrayList<>();

    public Dept() {
    }

    public Dept(Integer id, String name, Integer parentId) {
        this.id = id;
        this.name = name;
        this.parentId = parentId;
    }

    @Override
    public void add(Component component) {
        children.add(component);
    }

    @Override
    public void remove(Component component) {
        children.remove(component);
    }

    @Override
    public List<Component> getChildren() {
        return children;
    }

    @Override
    public String getName() {
        return name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public void setChildren(List<Component> children) {
        this.children = children;
    }

    public void setName(String name) {
        this.name = name;
    }
}
